﻿
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JsonRpc
{
    public class JsonRequest
    {
        /// <summary>
        /// JsonRpc调用客户端
        /// </summary>
        /// <param name="method">方法名字</param>
        /// <param name="sessinId">通信id</param>
        /// <param name="args">方法的参数信息</param>
        public JsonRequest(string method, long sessionId, params object[] args) {
            this.Method = method;
            this.SessionID = sessionId;
            this.FunctionArgs = args;
        }

        /// <summary>
        /// rpc的方法名称
        /// </summary>
        [JsonProperty("method")]
        public string Method { private set; get; }

        /// <summary>
        /// 远程rpc校验id
        /// </summary>
        [JsonProperty("id")]
        public long SessionID { private set; get; }

        /// <summary>
        /// rpc参数信息
        /// GO采用的是单个参数但是传递的时候可以传递结构体
        /// </summary>
        [JsonProperty("params")]
        public object[] FunctionArgs { private set; get; }

        /// <summary>
        /// 将rpc请求题编译为JSON文本
        /// </summary>
        /// <returns></returns>
        public string ToJsonString() {
            return Newtonsoft.Json.JsonConvert.SerializeObject(this, Formatting.Indented);
        }
    }
}
